﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>反馈类型</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="favicon.ico">
    @Html.Style("~/scripts/layuiadmin/layui/css/layui.css")
    @Html.Style("~/scripts/layuiadmin/style/admin.css")
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="query-filter">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <button type="button" class="layui-btn" id="btnAdd">新增</button>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <table id="typesList" lay-filter="typesList"></table>
            </div>
        </div>
    </div>
    <script type="text/html" id="typesListBar">
        {{# if(d.id > 0){}}
            {{# if(d.userName != 'null'){}}
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            {{#  } else { }}
            <a class="layui-btn layui-btn-xs layui-btn-disabled">编辑</a>
            {{#  } }}
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
        {{# }}}
    </script>
    @Html.Script("~/scripts/layuiadmin/layui/layui.js")
    <script type="text/javascript">
        layui.use(['form', 'layer', 'table'], function () {
            var layer = layui.layer,
                form = layui.form,
                table = layui.table,
                $ = layui.$,
                table = layui.table;
            initTypes();
            $('#btnAdd').click(showAddDialog);

            function showAddDialog() {
                layer.prompt({ title: '新增类型', formType: 0, offset: '100px' }, function (txt, index) {
                    $.post('/admin/feedback/add-type', { name: txt }, function (res) {
                        if (res.code == 1) {
                            table.reload('typesListTable');
                            layer.close(index);
                        } else {
                            layer.msg(res.msg);
                        }
                    });
                });
            }

            function showEditDialog(id, value) {
                layer.prompt({ title: '修改类型', formType: 0, offset: '100px', value: value }, function (txt, index) {
                    $.post('/admin/feedback/edit-type', { name: txt, id: id }, function (res) {
                        if (res.code == 1) {
                            table.reload('typesListTable');
                            layer.close(index);
                        } else {
                            layer.msg(res.msg);
                        }
                    });
                });
            }

            table.on('tool(typesList)', function (obj) {
                var layEvent = obj.event,
                    data = obj.data;

                if (layEvent === 'edit') {
                    showEditDialog(data.id, data.name);
                } else if (layEvent === 'delete') {
                    layer.confirm('确定要删除？', {
                        title: '提示',
                        btn: ['确定', '取消'],
                        offset: '100px'
                    }, function (index) {
                        $.post('/admin/feedback/delete-type', { id: data.id }, function (res) {
                            if (res.code == 1) {
                                table.reload('typesListTable');
                            } else {
                                layer.msg(res.msg);
                            }

                            layer.close(index);
                        });
                    });
                }
            });

            function initTypes() {
                table.render({
                    elem: '#typesList',
                    url: '/admin/feedback/list-type',
                    cellMinWidth: 95,
                    method: 'post',
                    page: true,
                    limit: 20,
                    limits: [10, 50, 100],
                    id: "typesListTable",
                    response: {
                        statusName: 'code' //规定数据状态的字段名称，默认：code
                        , statusCode: 1 //规定成功的状态码，默认：0
                        , msgName: 'msg' //规定状态信息的字段名称，默认：msg
                        , countName: 'count' //规定数据总数的字段名称，默认：count
                        , dataName: 'data' //规定数据列表的字段名称，默认：data
                    },
                    cols: [[
                        { field: 'id', title: '类型ID', align: "center" },
                        { field: 'name', title: '名称', align: "center" },
                        { field: 'addTime', title: '添加时间', align: "center" },
                        { title: '操作', templet: '#typesListBar', align: "center", width: 200 }
                    ]]
                });
            }
        });
    </script>
</body>
</html>